<template>
  <div class="app-container">
    <h3>日志列表</h3>
    <!-- 列表显示-->
    <el-table
      :data="list"
      border
      fit
      highlight-current-row>
      <el-table-column
        label="序号"
        width="70"
        align="center">
        <template slot-scope="scope">
          {{ (current - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column prop="orderNo" label="订单号"/>
      <el-table-column prop="payTime" label="支付时间"/>
      <el-table-column prop="createTime" label="支付金额">
        <template slot-scope="scope">
          {{scope.row.totalFee}}&nbsp;&nbsp;元
        </template>
      </el-table-column>
      <!--      <el-table-column prop="transactionId" label="流水号"/>-->
      <el-table-column prop="tradeState" label="交易状态"/>
      <!--<el-table-column prop="payType" label="支付类型"/>
      <el-table-column prop="createTime" label="创建时间"/>-->

      <el-table-column label="操作" width="300" align="center">
        <template slot-scope="scope">
          <el-button type="info" title="详情" size="mini" icon="el-icon-info" @click="getPayLogById(scope.row.id)">
          </el-button>
          <el-button type="danger" title="删除" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <el-pagination
      :current-page="current"
      :total="total"
      :page-size="limit"
      :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
      style="padding: 30px 0; text-align: center;"
      layout="sizes, prev, pager, next, jumper, ->, total, slot"
      @current-change="initPayLogList"
      @size-change="changeLimit"
    />

    <!-- 日志详情表单 -->
    <el-dialog :visible.sync="payLogFormVisible" title="订单详情">
      <el-form :model="payLogForm" label-width="120px">
        <el-form-item label="日志ID">
          <el-input readonly v-model="payLogForm.id"/>
        </el-form-item>
        <el-form-item label="订单号">
          <el-input readonly v-model="payLogForm.orderNo"/>
        </el-form-item>
        <el-form-item label="支付时间">
          <el-input readonly v-model="payLogForm.payTime"/>
        </el-form-item>
        <el-form-item label="交易流水号">
          <el-input readonly v-model="payLogForm.transactionId"/>
        </el-form-item>
        <el-form-item label="交易状态">
          <el-input readonly v-model="payLogForm.tradeState"/>
        </el-form-item>
        <el-form-item label="支付方式">
          <el-input readonly v-model="payLogForm.payType===1?'微信':'支付宝'"/>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-input readonly v-model="payLogForm.createTime"/>
        </el-form-item>
        <el-form-item label="更新时间">
          <el-input readonly v-model="payLogForm.updateTime"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="payLogFormVisible = false">确&nbsp;&nbsp;定</el-button>
        <!--<el-button type="primary" @click="saveOrUpdate">确 定</el-button>-->
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import paylog from "@/api/order/paylog";

  export default {
    name: "list",
    data() {
      return {
        list: [],//订单数据列表
        current: 1,//当前页
        limit: 5,//每页显示记录数
        total: 0,//总记录数
        orderQuery: {},//查询条件
        payLogForm: {},//日志对象
        payLogFormVisible: false,//订单详情表单是否显示
      }
    },
    created() {
      this.initPayLogList(1)
    },
    methods: {
      //初始化订单列表
      initPayLogList(current = 1) {
        this.current = current
        paylog.pagePaylogList(this.current, this.limit)
          .then(response => {
            this.list = response.data.items//记录集合
            this.total = response.data.total//总记录数
          })

      },

      // 当页码发生改变的时候
      changeLimit(limit) {
        console.log(limit)
        this.limit = limit
        this.initPayLogList(1)
      },
      //删除订单
      removeDataById(id) {
        this.$confirm('此操作将删除该日志, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {//点击确认调用
          paylog.removePaylogById(id)
            .then(response => {
              //提示
              this.$message({
                type: 'success',
                message: response.message
              })
              //刷新列表
              this.initPayLogList(1)
            })
            .catch(response => {
              //提示
              this.$message({
                type: 'error',
                message: response.message
              })
              //刷新列表
              this.initPayLogList(1)
            })
        })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            });
          });
      },
      //根据id查询订单详情
      getPayLogById(id) {
        this.payLogFormVisible = true
        paylog.getPaylog(id)
          .then(response => {
            this.payLogForm = response.data.paylog
          })
      },

    }

  }
</script>

<style scoped>

</style>
